#include "carwidget.h"


CarWidget::CarWidget(QWidget *parent)
  : QWidget(parent)
{
  uiInit();

  timer = new QTimer(this);
  timer->start(400);
  connect(timer, SIGNAL(timeout()), this, SLOT(testValue()));
}

CarWidget::~CarWidget()
{

}

void CarWidget::uiInit()
{
  this->setFixedSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  this->setWindowFlags(Qt::FramelessWindowHint);

 //设置背景色
  QPalette pal(this->palette());
  pal.setColor(QPalette::Background, Qt::black);
  this->setAutoFillBackground(true);
  this->setPalette(pal);

  odo = new OdoLabel(this);
  odo->setGeometry(317, 225, 150, 30);
  odo->setOdoValue(999999);

  //档位
  assistLabel = new Assist(this);
  assistLabel->setGeometry(15, 50, 105, 175);
  assistLabel->setAssistMode(Assist::NEUTRAL);

  //电压电流
  voltLabe = new VoltLabel(this);
  voltLabe->setGeometry(362, 50, 106, 175);

  //警报图表
  warnLabel = new WarnLabel(this);
  warnLabel->setGeometry(15, 0, 155, 50);

  //中间表盘
  speedLabel = new SpeedBoard(this);
  speedLabel->setGeometry(123, 24, 231, 227);
  speedLabel->setSpeedValue(50);
}

void CarWidget::testValue()
{
  static quint8 i;

  if (i++ > 120)
    i = 0;
  speedLabel->setSpeedValue(i);

  switch (i % 4) {
    case 0:
      assistLabel->setAssistMode(Assist::PARK);
    break;
    case 1:
      assistLabel->setAssistMode(Assist::REVERSE);
    break;
    case 2:
      assistLabel->setAssistMode(Assist::NEUTRAL);
    break;
    case 3:
      assistLabel->setAssistMode(Assist::DRIVE);
    break;
    default:
    break;
  }

  odo->setOdoValue(i);
}
